<template>
	<view class="content">
		<view class="activity" v-for="(item,index) in activities" :key="index" @tap="go_activity_detail(index)">
			<view class="top">
				<text>{{item.activityTitle}}</text>
				<view class="time">{{formatTime(item.startTime)}}</view>
			</view>
			<view class="mid">
				<text>{{item.maxPeople}} 人</text>
			</view>
			<view class="bottom">
				<text>{{item.activityAddress}}</text>
				<view class="info" @tap.stop="go_user_detail(item.userId)">
					<image :src="getRealPath(item.imgUrl)" mode=""></image>
					<text>{{item.nickName}}</text>
				</view>
			</view>
		</view>
		<image class="add" @tap="go_add()" src="../../static/images/add.png"></image>
		<image class="my" @tap="go_my()" src="../../static/images/my.png"></image>
		<view v-if="expresses.length!=0" style="margin-bottom: 20upx;height: 80upx; font-size: 28upx;color: #999999;text-align: center; line-height: 80upx;width: 92;">{{content}}</view>
	</view>
</template>

<script>
	import utils from "../../static/js/utils.js";
	export default {
		data() {
			return {
				activities: [],
				pageId:0,
				content:''
			}
		},
		onShow() {
			this.getActivity(0, 0);
		},
		onReachBottom() {
			if (this.content != "已经到底了") {
				let pId = this.pageId;
				this.getActivity(pId + 1, 1);
			}
		
		},
		onPullDownRefresh() {
			this.getActivity(0, 0);
		},
		methods: {
			go_add(){
				uni.navigateTo({
					url: 'addactivity'
				});
			},
			go_my(){
					uni.navigateTo({
					url: 'myactivity'
				});
			},
			go_activity_detail(index){
				uni.navigateTo({
					url: 'activitydetail?activity='+JSON.stringify(this.activities[index])
				});
			},
			getActivity(pageId, type) {
				let that = this;
				utils.get("activity/index", {
					pageId
				}, function(data) {
					if (type == 0) {
						that.content = "";
						that.activities = data;
						uni.stopPullDownRefresh();
					} else {
						if (data.length == 0) {
							that.content = "已经到底了"
						} else {
							that.activities.push.apply(that.activities, data);
							that.pageId++;
						}
			
					}
				});
			},
			getRealPath(path) {
				return utils.baseImgUrl + path;
			},
			formatTime(timestamp) {
				var da = new Date(timestamp);
				return  (da.getMonth() + 1) + "月" + da.getDate()+"日 "+da.getHours()+":" +da.getMinutes();
			},
			
			go_user_detail(userId){
				uni.navigateTo({
					url: '../usercenter/userinfo?userId='+userId
				});
			},
			
		}
	}
</script>

<style>
	.content {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.add {
		height: 80upx;
		width: 80upx;
		position: fixed;
		right: 40upx;
		bottom: 140upx;
	}
	.my{
		height: 80upx;
		width: 80upx;
		position: fixed;
		right: 40upx;
		bottom: 40upx;
	}
	.activity {
		width: 92%;
		height: 180upx;
		display: flex;
		flex-direction: column;
		
		box-shadow: inset 0px -1px 1px -1px #dcdcdc;
	}
	.top{
		width: 100%;
		height: 90upx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-top: 10upx;
	}
	.top text {
		font-size: 30upx;
		font-weight: 600;
		overflow: hidden;
		white-space: nowrap;
		max-width: 84%;
	}
	.top view {
		padding: 4upx 8upx;
		border: 1px solid #2E77ED;
		color: #2E77ED;
		font-size: 22upx;
		height: 32upx;
		border-radius: 4upx;
	}
	.mid {
		font-size: 24upx;
		color: #999999;
		height: 40upx;
	}
	.bottom{
		height: 90upx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		font-size: 24upx;
		color: #999999;
	}
	.info {
		display: flex;
		flex-direction: row;
		height: 90upx;
		align-items: center;
	}
	.info image {
		width: 30upx;
		height: 30upx;
		margin-right: 14upx;
	}
	
</style>
